//
//  QLSkillInvitedMeetListVC.m
//  神约
//
//  Created by qlwl on 17/2/16.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLSkillInvitedMeetListVC.h"
#import "QLSkillInvitedMeetListCell.h"
#import "QLAllInvitedMeetListModel.h"

@interface QLSkillInvitedMeetListVC ()
@property (weak, nonatomic) IBOutlet UITableView *tableView1;
@property (weak, nonatomic) IBOutlet UITableView *tableView2;

@end

@implementation QLSkillInvitedMeetListVC
{
    NSMutableArray * _dataArray1;
    NSMutableArray * _dataArray2;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _dataArray1 = [[NSMutableArray alloc] init];
    _dataArray2 = [[NSMutableArray alloc] init];
    [self netWorkingWithPayType:2];
}

#pragma mark TabDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.tableView1) {
        return _dataArray1.count;
    }else if (tableView == self.tableView2){
        return _dataArray2.count;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    QLSkillInvitedMeetListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QLSkillInvitedMeetListCell"];
    QLAllInvitedMeetListModel * meetModel = nil;
    if (tableView == self.tableView1) {
        meetModel = _dataArray1[indexPath.row];
    }else{
        meetModel = _dataArray2[indexPath.row];
    }
    [cell.headIma QL_setImageWithURL:[NSString stringWithFormat:@"%@%@",HTTP_BaseURL,meetModel.headpicurl] placeholderImage:nil];
    cell.userNameLab.text = meetModel.userName;
    NSString * ageStr = nil;
    if (meetModel.sex.length > 0) {
        ageStr = [meetModel.sex intValue] == 0?@"女":@"男";
    }
    if (meetModel.age.length > 0) {
        ageStr = [NSString stringWithFormat:@"%@%@岁",ageStr,NotNullClass(meetModel.age)];
    }
    cell.ageLab.text = ageStr;
    cell.distanceLab.text = [NSString stringWithFormat:@"%.2fkm",meetModel.distince/1000];
    cell.addressLab.text = meetModel.destination;
    cell.meetPriceLab.text = [NSString stringWithFormat:@"￥%.0f",meetModel.servicePrice];
    cell.publishTimeLab.text = meetModel.createtime;
    cell.helpLab.text = @"我要求助";
    cell.titNameLab.text = meetModel.typeName;
    cell.describeLab.text = nil;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 130;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark netWorking
- (void)netWorkingWithPayType:(int)category //2表示技能互助-我要求助,3表示技能互助-我能帮助
{
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc] init];
    QLLoginModel * loginModel = [QLLoginModel accountFromSandbox];
    postDict[@"userid"] = loginModel.userId;
    postDict[@"currentPage"] = @"1";
    postDict[@"pageSize"] = @"10";
    postDict[@"category"] = [NSNumber numberWithInt:category];
//    postDict[@"chargeType"] = @"";
    //    postDict[@""] = @"";
    //    postDict[@""] = @"";
    //    postDict[@""] = @"";
    [QLNetWorking postJSONWithUrl:QLAllPublishLifeListURl parameters:postDict isJosnRequest:YES rogress:nil success:^(id result) {
        NSLog(@"%@",result);
        if ([QLNetWorking sucess:[result objectForKey:@"mobileHead"] and:@"code" EqualToString:@"success"]) {
            NSArray * array = [QLAllInvitedMeetListModel mj_objectArrayWithKeyValuesArray:[[result objectForKey:@"mobileBody"] objectForKey:@"data"]];
            if (category == 2) {
                [_dataArray1 addObjectsFromArray:array];
                [self.tableView1 reloadData];
            }else if(category == 3){
                [_dataArray2 addObjectsFromArray:array];
                [self.tableView2 reloadData];
            }
        }
    } fail:^(NSError *error) {
        
    }];
}



@end
